#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/4/28 14:44
# @Author  : 王凯
# @File    : __init__.py.py
# @Project : scrapy_spider
# from pathlib import Path
#
# import jpype
#
# JAR_PATH = rf"{Path(__file__).parent.as_posix()}/pdd-anti-token-jar-with-dependencies.jar"  # 对应jar地址
#
# jvmPath = jpype.getDefaultJVMPath()
#
#
# class PddAntiTokenSo:
#     def __enter__(self):
#         jpype.startJVM(jvmPath, "-Dfile.encoding=utf-8", f"-Djava.class.path={JAR_PATH}")
#         self.java = jpype.JClass("pdd.anti.token.PddAntiToken")
#         return self
#
#     def gen_anti_content(self, time, device_id=None):
#         if device_id:
#             anti_content = self.java.getToken([str(time), device_id])
#         else:
#             anti_content = self.java.getToken([str(time)])
#         # 将 anti_content 的 java.lang.String类型 转为 python 的 str
#         anti_content = str(anti_content)
#         return anti_content
#
#     def __exit__(self, exc_type, exc_val, exc_tb):
#         jpype.shutdownJVM()
